<template>
	<view class="kedou_main">
	
	
		<view class="kedou_panel wanl-user-order padding-sm margin-bj" style="margin-top: 50rpx;">
			<view>
					<view class="wanl-text-bg text-lg text-bold6">
						<text class="vip-round">◎</text>
						<text v-if="userInfo.kd_vip>0">VIP</text>
						<text v-else>普通会员</text>
					</view>							
			</view>
			<view class="project text-sm wanl-gray-dark">
				<view style="line-height: 1.8;" @tap="$wanlshop.auth('/pages/user/newTeam/kedouIntegral')">
					<!--<view class="wanl-text-bg text-lg text-bold6">分红收益率 {{fenhong.rate}}%</view>-->
					<view class="wanl-text-bg text-lg text-bold6">春节符号价格:{{scoredata.rate}}</view>
				</view>					
					
			</view>
			<view style="display: flex;align-items: center;justify-content: space-around;margin: 25rpx;" >
				<view @tap="exchange();" class="kedouIntegral_button" style="margin:auto;" >
					<text >兑换</text>									
				</view>
				<view @tap="transfer();" class="kedouIntegral_button" style="margin:auto;" >
					<text >转赠</text>									
				</view>
			</view>
	
			<view class="project text-sm wanl-gray-dark" v-if="false">
				<view style="line-height: 1.8;" >
					<view class="wanl-text-bg text-lg text-bold6">
						<text class="wanl-text-warn">封顶分红</text>
					</view>
					
					<!--
					<view class="wanl-text-bg text-lg text-bold6">{{ userInfo.kd_score||0 }}</view>
					封顶分红
					-->
				</view>
				<view style="line-height: 1.8;" >
					<view class="wanl-text-bg text-lg text-bold6">{{scoredata.data1}}</view>
					
				</view>						
			</view>
			<view class="project text-sm wanl-gray-dark" >
				<view style="line-height: 1.8;"  @tap="$wanlshop.auth('/pages/user/newTeam/freezen')">
					<view class="wanl-text-bg text-lg text-bold6">
						<text class="wanl-text-warn">待分红</text>
					</view>
				</view>
				<view style="line-height: 1.8;" >
					<view class="wanl-text-bg text-lg "  style="    width: 200px;">{{scoredata.data7}}</view>
					
				</view>						
			</view>
			<view class="project text-sm wanl-gray-dark">
				<view style="line-height: 1.8;"  @tap="$wanlshop.auth('/pages/user/newTeam/freezen')">
					<view class="wanl-text-bg text-lg text-bold6">
						<text class="wanl-text-warn">已分红</text>
					</view>
				</view>
				<view style="line-height: 1.8;" >
					<view class="wanl-text-bg text-lg "  style="    width: 200px;">{{scoredata.user_take_freezen}}</view>
					
				</view>						
			</view>
			<view class="project text-sm wanl-gray-dark" v-if="false">
				<view style="line-height: 1.8;"  @tap="$wanlshop.auth('/pages/user/newTeam/freezen')">
					<view class="wanl-text-bg text-lg text-bold6">
						<text class="wanl-text-warn">总分红<BR/>(已领/待领)</text>
					</view>
				</view>
				<view style="line-height: 1.8;" >
					<view class="wanl-text-bg text-lg "  style="    width: 200px;">{{scoredata.user_taked_sum}}/{{scoredata.user_can_take}}</view>
					
				</view>						
			</view>
			<view class="project text-sm wanl-gray-dark" v-if="false">
				<view style="line-height: 1.8;" >
					<view class="wanl-text-bg text-lg text-bold6">
						<text class="wanl-text-warn">已分红</text>
					</view>
				</view>
				<view style="line-height: 1.8;" >
					<view class="wanl-text-bg text-lg ">{{scoredata.data2}}</view>
					
				</view>						
			</view>
			<view class="project text-sm wanl-gray-dark" v-if="false">
				<view style="line-height: 1.8;"  @tap="$wanlshop.auth('/pages/user/newTeam/kdj')">
					<view class="wanl-text-bg text-lg text-bold6">
						<text class="wanl-text-warn">春节符号<BR/>(已领/待领)</text>
					</view>
				</view>
				<view style="line-height: 1.8;" >
					<view class="wanl-text-bg text-lg " style="    width: 200px;">{{scoredata.user_take_freezen}}/{{scoredata.freezen}}</view>
					
				</view>						
			</view>
		
			<view class="project text-sm wanl-gray-dark">
				<view style="line-height: 1.8;">
					<view class="wanl-text-bg text-lg text-bold6" @tap="$wanlshop.auth('/pages/user/newTeam/prize')">
						<text class="wanl-text-warn">管理分红</text>
					</view>
				</view>
				<view style="line-height: 1.8;" >
					<view class="wanl-text-bg text-lg"  style="    width: 200px;">{{scoredata.user_prize}}</view>
					
				</view>	
								
			</view>
			<view style="height:10px"></view>
			<view class="project text-sm wanl-gray-dark">
				<view class="small_button" @tap="getPrize" style="margin:auto;text-align:center" >
					领取团队分红
				</view>
				<view class="small_button" @tap="getKdj" style="margin:auto;text-align:center" >
					每日领取春节符号
				</view>
			</view>
		</view>
		
		
		<view class="kedou_panel wanl-user-order padding-sm margin-bj" style="margin-top: 50rpx;" v-if="false">
			<view>
					<view class="wanl-text-bg text-lg text-bold6">						
						分红确权值					
					</view>							
			</view>
			<view class="project text-sm wanl-gray-dark" style="display:block;">
				<view class="list-text">
					<view class="wanl-text-bg text-lg text-bold6">剩余额度:{{scoredata.quota}}</view>					
				</view>					
				<view class="list-text">
					<view class="wanl-text-bg text-lg text-bold6">总兑换量:{{scoredata.amount}}</view>					
				</view>	
				<view class="list-text">
					<view class="wanl-text-bg text-lg text-bold6">兑换比例:{{scoredata.rate}}</view>					
				</view>	
			</view>
		</view>
		<!-- <view class="wanl-you-like" :style="{ backgroundImage: 'url(' + $wanlshop.appstc('/common/guess_you_like_it.png') + ')' }"></view> -->
		<!-- <wanl-product :dataList="likeData"/> -->
		<!-- <uni-load-more :status="status" :content-text="contentText" /> -->
		<!-- 分享 -->
		<view
			class="cu-modal wanl-share "
			:class="modalName == 'share' ? 'show' : ''"
			@tap="hideModal()"
		>
			<view v-if="modalName == 'share'" class="cu-dialog" @tap.stop="">
				<wanl-poster
					ref="wanlPoster"
					page="pages/user"
					:scene="{qr:'u'}"
					@success="posterSuccess"
					@change="hideModal"
				/>
			</view>
		</view>
		<view class="edgeInsetBottom"></view>
	</view>
</template>

<script>
const app = getApp();
import { mapState } from 'vuex';
export default {
	data() {
		return {
			modalName: '',
			headerOpacity: 0,
			// 上拉刷新
			reload: true,
			likeData: [],
			current_page: 1, //当前页码
			last_page: 1, //总页码
			status: 'loading',
			contentText: {
				contentdown: ' ',
				contentrefresh: '正在加载...',
				contentnomore: '没有更多数据了'
			},
			userInfo:{},
			is_card:"1",//是否隐藏 1 隐藏
			query:'',
			fenhong:{ 
				level:1, //参与的分红级别
				rate:300, //分红倍率
			},
			isShowModal:false,
			vipvideo:{},
			selectVip:0,
			viplist:[{
				name: 'VIP1 500,300%',
				remark:'',				
				//disabled: false,
				select:false,
			},{
				name: 'VIP2 3000,400%',
				//disabled: false,
				remark:'',
				select:false
			},{
				name: 'VIP3 5000,500%',
				//disabled: false,
				remark:'',
				select:false
			}],
			scoredata:{
				data1:0,
				data2:0,
				data3:0,
				data4:0,
				data5:0,
				data6:0,
				data7:0,
				amount:0,
				quota:0,
				rate:0.1,
				freezen:0,
			},
			
		};
	},
	computed: {
		...mapState(['user', 'statistics','common'])
	},
	onPullDownRefresh() {
		this.loadData();
	},
	onShow() {
		setTimeout(()=> {
			uni.setNavigationBarColor({  
				frontColor: this.$store.state.common.appStyle.user_font_color == 'light'?'#ffffff':'#000000',  
				backgroundColor: this.$store.state.common.appStyle.user_nav_color
		    })  
		}, 200);
		if (uni.getStorageSync('wanlshop:user')) {
			this.loadData();
		}
		//this.getCard();
		
	},
	onLoad(query) {
		this.query = query;
		if(query.hasOwnProperty('scene')){
			let scene = decodeURIComponent(query.scene);
				scene = this.$wanlshop.getParam(scene);
			console.log('小程序码进入：', scene);
		}
		this.loadlikeData();
	},
	onPageScroll(e) {
		let tmpY = 50;
		e.scrollTop = e.scrollTop > tmpY ? 50 : e.scrollTop; //如果当前高度大于250则250否则当前高度
		this.headerOpacity = e.scrollTop * (1 / tmpY); //$headerOpacity 赋值当前高度x（1÷250）
	},
	onReachBottom() {
		//判断是否最后一页
		if (this.current_page >= this.last_page) {
			this.status = 'noMore';
		} else {
			this.reload = false;
			this.current_page = this.current_page + 1; //页码+1
			this.status = 'loading';
			this.loadlikeData();
		}
	},
	methods: {
		gokdj(){
			this.$wanlshop.auth('/pages/user/newTeam/kdj');
			//this.$wanlshop.auth('/pages/user/work/index');
		},
		transfer(){
			this.$wanlshop.auth('/pages/user/money/transfer_kdj');
		},
		exchange(){
			uni.showModal({
				title: '请填入要兑换的春节符号数量',
				content: '',
				editable: true, //是否显示输入框
				placeholderText: this.userInfo.kdj, //输入框提示内容
				confirmText: '确认',
				cancelText: '取消',
				success:   (res) => {
					if (res.confirm) {
						console.log('输入的内容：', res.content);
						if(!res.content) return this.$wanlshop.msg('请输入有效数量');
						var val = parseFloat(res.content);
						if(val<0||val>this.userInfo.kdj) return this.$wanlshop.msg('请输入有效数量')
						this.buyvip(res.content);
					}
				}
			})
			
		},
		buyvip(val){
			if(this.userInfo.id==""){
				this.showMsg("请登录","warn");
				
				return;
			}
			uni.request({
				url:"/Appapi/buyvipnew",
				method:"GET",
				data:{uid:this.userInfo.id,need_score:val},
				success: (res) => {
					//this.is_card=res.data
					if(res.code==1){
						this.showMsg(res.msg,"warn");
						return;
					}
					this.showMsg(res.msg,"warn");
					console.log(res,'升级vip');
					//this.isShowModal = false;
					this.loadData();
				}
			});
		},
		async uplevel(){
			var uid = this.userInfo.id;
			var need_score = 500;
			
			
			if(this.selectVip==0){
				this.showMsg("请选择一个选项","info");
				return;
			}
			console.log(this.selectVip);
			//return;
			//this.showVipSelect();			
			//兑换或升级vip,需要选择vip级别
			await uni.request({
				url:"/Appapi/buyvip",
				method:"GET",
				data:{uid:uid,need_score:need_score,vip:this.selectVip},
				success: (res) => {
					//this.is_card=res.data
					this.showMsg(res.msg,"warn");
					console.log(res,'升级vip');
					this.isShowModal = false;
					this.loadData();
				}
			});
		},
		getKdj(){
			uni.request({
				url:"/Appapi/getkdj",
				method:"GET",
				data:{uid:this.userInfo.id},
				success: (res) => {
					//this.is_card=res.data
					this.showMsg(res.data.msg,"warn");					
					this.getScoreReport();
				}
			});
		},
		async getPrize(){ //领取
			await uni.request({
				url:"/Appapi/getprize",
				method:"GET",
				data:{uid:this.userInfo.id},
				success: (res) => {
					//this.is_card=res.data
					this.showMsg(res.msg,"warn");					
					this.getScoreReport();
				}
			});
		},
		async getScoreReport(){
			var that = this;
			console.log("uid",this.user.id);
			await uni.request({
				url:"/Appapi/scorereport",
				method:"POST",
				data:{
					uid:this.user.id
				},
				success: (res) => {						
					//console.log("scorereport",res.data);
					that.scoredata = res.data;
				}
			})
		},

		async loadData() {
			await uni.request({
				url: '/wanlshop/user/refresh',
				method: 'POST',
				success: res => {
					
					this.userInfo=res.data.userinfo
					this.$store.commit('statistics/edit', res.data.statistics);
					this.$store.commit('user/setUserInfo', res.data.userinfo);
					console.log("user",this.userInfo);
					
					if(this.userInfo.kd_vip==1){
						this.fenhong.rate = 300;						
					}else if(this.userInfo.kd_vip==2){
						this.fenhong.rate = 400;					
					}else if(this.userInfo.kd_vip==3){
						this.fenhong.rate = 500;
					}
					else{
						this.fenhong.rate = 0;						
					}
					if(this.userInfo.kd_vip!=3){
						
					}
					
					this.getScoreReport();
				}
			});
			uni.stopPullDownRefresh();
		},		
		// 滚动底部加载猜你喜欢
		async loadlikeData() {
			await uni.request({
				url: '/wanlshop/product/likes?pages=user',
				data: {
					page: this.current_page
				},
				success: res => {
					this.likeData = this.reload ? res.data.data : this.likeData.concat(res.data.data); //评论数据 追加
					this.current_page = res.data.current_page; //当前页码
					this.last_page = res.data.last_page; //总页码
					this.status = res.data.total == 0 ? 'noMore' : 'more';
				}
			});
		},
		// 弹出层
		showModal(name) {
			if(name == 'share') {
				if(this.user.isLogin){
					this.modalName = name;
				}else{
					this.$wanlshop.to('/pages/user/auth/auth');
				}
			}else{
				this.modalName = name;
			}
		},
		hideModal() {
			this.modalName = null;
		},
		showMsg(title = '', icon = 'none',duration = 2000){
			this.appShowToast(title, icon, false, duration);
		},
		appShowToast(title = '', icon = 'none', mask = true, duration = 2000, position = 'center') {
			uni.hideLoading();
			return uni.showToast({
				title: title,
				icon: icon,
				mask: mask,
				duration: duration,
				position: position
			});
		},
		posterSuccess(e){},
		// 帮助
		help() {
			this.$wanlshop.to('/pages/user/help');
		},
		// 设置
		setting() {
			this.$wanlshop.to('/pages/user/setting/setting');
		},
		portrai() {
			this.$wanlshop.to('/pages/user/portrait/portrait');
		}
	}
};
</script>

<style>

@import "../user";
@import "report";


</style>
